package cn.edu.scau.dormitory_management_system.module.examine.controller;

import cn.edu.scau.dormitory_management_system.constant.Consts;
import cn.edu.scau.dormitory_management_system.module.examine.entity.FlowEntity;
import cn.edu.scau.dormitory_management_system.module.examine.entity.FlowNodeEntity;
import cn.edu.scau.dormitory_management_system.module.examine.entity.VO.FlowVO;
import cn.edu.scau.dormitory_management_system.module.examine.service.FlowNodeService;
import cn.edu.scau.dormitory_management_system.module.examine.service.FlowService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Vizzk
 * @description：TODO
 * @date ：2021/8/5 15:49
 */
@RestController
@RequestMapping("/admin/flow")
public class FlowController {
    @Autowired
    private FlowService flowService;
    @Autowired
    private FlowNodeService flowNodeService;

    @GetMapping("/getFlowByFlowId")
    public Object getFlowByFlowId(Integer flowId){
        JSONObject jsonObject = new JSONObject();
        FlowVO flowVO = new FlowVO();
        FlowEntity flow = flowService.getById(flowId);
        List<FlowNodeEntity> nodes = flowNodeService.listFlowNodesByFlowId(flowId);
        flowVO.setFlow(flow);
        flowVO.setNodes(nodes);

        try {
            jsonObject.put(Consts.CODE, 200);
            jsonObject.put(Consts.MSG, "查询审核流程成功");
            jsonObject.put("flowVO", flowVO);
        }
        catch (Exception e){
            jsonObject.put(Consts.CODE, 0);
            jsonObject.put(Consts.MSG, "获取审核流程失败");
        }
        return jsonObject;
    }
}
